<template>
 <!-- <el-dialog :title="title"
         :visible.sync="dialogVisible">
    <div slot="header" class="ivu-modal-header-inner">
      <span>{{title}}</span>
      <a class="ivu-modal-close">
        <i v-if="minMax" style="font-size: 28px;" @click="minMaxHandler"
           :class="fullscreen?'ivu-icon ivu-icon-ios-photos-outline':'ivu-icon ivu-icon-ios-square-outline'"></i>
        <i v-if="closable" @click="close" class="ivu-icon ivu-icon-ios-close"></i>
      </a>
    </div>
    <MldContent ref='mldContent' :params="params"></MldContent>
    <div slot="footer" class="dialog-footer">
      <Button v-if="showCancel" @click='cancelHandler' size='large'>{{textCancel}}</Button>
      <Button v-if="showOk" :loading='buttonLoading' type="primary" size='large' @click='okHandler'>{{textOk}}</Button>
    </div>
  </el-dialog>-->
  <el-dialog class="nofooter" :fullscreen="fullscreen" :title="title" :width="width" :top="top" :show-close="showClose" :visible.sync="dialogFormVisible" :close-on-click-modal="false">
    <el-row slot="title" >
      <el-col :span="20">
        {{title}}
      </el-col>
      <el-col :span="4" style="text-align: right">
        <el-button type="text" icon="el-icon-full-screen" @click="fullscreen=!fullscreen"></el-button>
      </el-col>
    </el-row>
    <MldContent ref='mldContent' :params="params" :parents="parent" :dialog="this"></MldContent>
    <!--<div slot="footer" class="dialog-footer">
      <el-button v-if="showCancel" @click='cancelHandler'>{{textCancel}}</el-button>
      <el-button v-if="showOk" :loading='buttonLoading' type="primary" @click='okHandler'>{{textOk}}</el-button>
    </div>-->
    <div slot="footer" class="dialog-footer"></div>
  </el-dialog>
</template>
<script>
export default {
  data () {
    return {
      title: '',
      minMax: true,
      visible: true,
      dialogVisible: false,
      fullscreen: false,
      width: '800px',
      top: '15vh',
      buttonLoading: false,
      dialogFormVisible: true,
      parent: null,
      params: {},
      showCancel: true,
      showOk: true,
      textCancel: '关闭',
      textOk: '保存',
      closable: true,
      refreshFlag: false,
      showClose: false
    }
  },
  created () {
    // if (this.parent) {
    //   if (typeof this.parent.getCurrentRow === 'function') {
    //     this.params = this.parent.getCurrentRow()
    //   }
    // }
  },
  methods: {
    minMaxHandler () {
      this.fullscreen = !this.fullscreen
    },
    close () {
      if (this.$refs['mldContent'].closeRefreshParent) {
        this.parent.handleRefresh(this.parent)
      }
      this.visible = false
      this.remove()
    },
    remove: function () {
      setTimeout(() => {
        this.destroy()
      }, 300)
    },
    destroy: function () {
      this.$destroy()
      document.body.removeChild(this.$el)
    },
    okHandler () {
      let $this = this
      if (typeof this.$refs['mldContent'].submit === 'function' || typeof this.$refs['mldContent'].selectCallback === 'function') {
        if (typeof this.$refs['mldContent'].submit === 'function') {
          this.$confirm('', '是否退出并保存当前操作？', {
            distinguishCancelAndClose: true,
            confirmButtonText: '保存',
            cancelButtonText: '不保存'
          }).then(() => {
            $this.buttonLoading = true
            this.$refs['mldContent'].submit().then(res => {
              if (res.code === '000') {
                this.$message.success(res.message ? res.message : '保存成功')
                if ($this.saveClose) {
                  $this.close()
                  if ($this.parent) {
                    if (typeof $this.parent.handleRefresh === 'function') {
                      $this.parent.handleRefresh($this.parent)
                    }
                  }
                } else {
                  $this.buttonLoading = false
                }
              } else if (res.code === '111') {
                $this.close()
                $this.buttonLoading = false
              } else {
                this.$message.error(res.message ? res.message : '保存失败')
                $this.buttonLoading = false
              }
            }).catch(e => {
              console.log('校验不通过' + e)
              $this.buttonLoading = false
            })
          }).catch(action => {
          })
        }
        if (typeof this.$refs['mldContent'].selectCallback === 'function') {
          this.$refs['mldContent'].selectCallback(this.parent).then(res => {
            this.close()
          }).catch(e => {
            console.log(e)
          })
        }
      } else {
        this.okx(this)
        this.close()
      }
    },
    cancelHandler () {
      if (this.refreshFlag) {
        let $this = this
        if ($this.parent) {
          if (typeof $this.parent.handleRefresh === 'function') {
            $this.parent.handleRefresh($this.parent)
          }
        }
      }
      this.cancel(this)
      this.close()
    }
  }
}
</script>

<style>
  .el-dialog__body {
    padding: 16px 24px 0px 24px !important;
  }
  .el-button--text{
    color: #00A4FF !important;
  }
</style>
